package org.aisino.shdzfp.vistool.swing;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.net.URL;
import java.util.Enumeration;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

import org.apache.log4j.Logger;
import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;

@SuppressWarnings("serial")
public class VisTool extends JFrame {

	private final static Logger log = Logger.getLogger(VisTool.class);

	public static int WIDTH = 768;
	public static int HEIGHT = 438;

	public static URL url;

	static {
		url = VisTool.class.getResource("/0.png");
	}
	
	public VisTool() {
		setTitle("WoRi's Screwdriver");
		setSize(WIDTH, HEIGHT);
		setLocationByPlatform(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		setResizable(false);
		setIconImage(new ImageIcon(url).getImage());
	}

	private static void os() {

		InitGlobalFont(new Font("微软雅黑", Font.PLAIN, 10));
		try {
			org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
			BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.translucencySmallShadow;
			org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
			UIManager.put("RootPane.setupButtonVisible", false);
			// BeautyEyeLNFHelper.translucencyAtFrameInactive = false;
			// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			System.err.println("set skin fail!");
		}
	}

	private static void InitGlobalFont(Font font) {
		FontUIResource fontRes = new FontUIResource(font);
		for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
			Object key = keys.nextElement();
			Object value = UIManager.get(key);
			if (value instanceof FontUIResource) {
				UIManager.put(key, fontRes);
			}
		}
	}

	/**
	 * 使用当前系统风格
	 */
	private static void setOSStyle() {
		if (UIManager.getLookAndFeel().isSupportedLookAndFeel()) {
			final String platform = UIManager.getSystemLookAndFeelClassName();
			// If the current Look & Feel does not match the platform Look &
			// Feel,
			// change it so it does.
			if (!UIManager.getLookAndFeel().getName().equals(platform)) {
				try {
					UIManager.setLookAndFeel(platform);
				} catch (Exception exception) {
					exception.printStackTrace();
				}
			}
		}
	}

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				os();
//				setOSStyle();
				VisTool frame = new VisTool();
				
				JPanel panel = new JPanel();
				frame.add(panel);
				panel.setLayout(new BorderLayout());
				
				JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.RIGHT); // 设置选项卡在坐标
				
				JPanel p1 = new MsgPanel();
				JPanel p2 = new PasswordCreatePanel();
				JPanel p3 = new XmlReader();
				tabbedPane.add("Encode/Decode", p1);
				tabbedPane.add("GeneratePwd", p2);
				tabbedPane.add("XmlReader", p3);
				
				panel.add(tabbedPane, BorderLayout.CENTER);
//				frame.add(tabbedPane, BorderLayout.CENTER);
				frame.setVisible(true);
			}
		});
	}

}
